package edu.unmsm.fisi.taller2.mvcdemo.controller.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.unmsm.fisi.taller2.mvcdemo.controller.RequestHandler;
import edu.unmsm.fisi.taller2.mvcdemo.dao.UserDao;
import edu.unmsm.fisi.taller2.mvcdemo.model.UserBean;

public class ShowRecordRequestHandler implements RequestHandler {
    private UserDao userDao;
    public ShowRecordRequestHandler(){
        userDao = new UserDao();
    }
    @Override
    public String handleRequest(HttpServletRequest request, HttpServletResponse response) {
        String name = request.getParameter("name");
        if (name == null){
            return "enterName.jsp";
        }else {
            UserBean user = userDao.getUser(name);
            if (user == null){
                return "sorryNotFound.jsp";
            }else{
                request.setAttribute("user", user);
                return "showInfo.jsp";
            }
        }
    }

}
